<template>
  <el-table
    v-loading="loading"
    :data="tableData"
    border
    style="width: 100%"
    @selection-change="$emit('selection-change', $event)"
  >
    <!-- 复选列 -->
    <el-table-column type="selection" width="55" align="center" />

    <!-- 常规列 -->
    <el-table-column type="index" label="序号" width="60" align="center"/>
    <el-table-column prop="probeName" label="探针名称" align="center" />
    <!--如果审定结果是等待审定则显示审定时间，否则审定时间用-代替-->
    <el-table-column prop="submitApproveTime" label="提交时间" width="180" align="center"/>
    <el-table-column
      prop="submitApproveTime"
      label="校对时间"
      width="180"
      align="center"
      :formatter="(row) => {
        return row.approveTime !== '' ? row.approveTime : '-';
      }"
    />
    <el-table-column prop="approveResult" label="审定结果" width="120" align="center"/>
    <!-- 操作列 -->
    <el-table-column label="操作" width="560" align="center">
      <template #default="{ row }">
        <el-button
          size="mini"
          type="text"
          icon="el-icon-document"
          @click="$emit('view-draw', row)"
          v-hasPermi="['probe:version:view']"
        >查看图纸</el-button>
        <template v-if="row.approveResult=== '未通过'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            @click="$emit('view-comments', row)"
            v-hasPermi="['probe:version:submit']"
          >查看批注</el-button>
        </template>
        <!-- 动态操作按钮 -->
        <template v-if="row.approveResult=== '等待审定'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            @click="handleRejctApprove(row)"
            v-hasPermi="['probe:version:submit']"
          >批注并退回</el-button>
        </template>
        <template v-if="row.approveResult==='等待审定'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-message"
            @click="handleSubmitApprovement(row)"
            v-hasPermi="['probe:version:comment']"
          >确认发布</el-button>
        </template>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: 'approveComponent',
  props: {
    // 表格数据（数组）
    tableData: {
      type: Array,
      required: true,
      default: () => []
    },
    // 加载状态（布尔值）
    loading: {
      type: Boolean,
      default: false
    },
    // 其他数据（任意类型）
    extraConfig: {
      type: Object,
      default: () => ({})
    }
  },
  methods:{
    handleRejctApprove(row) {
      console.log('approve',this.tableData)
      console.log('reject-lastStage', )
      // 处理批注并退回的逻辑
      const note = "submitToApproveReject"
      this.$emit('reject-lastStage', row,note);
    },
    handleSubmitApprovement(row) {
      console.log('approve')
      console.log('submit-nextStage', row)
      // 处理提交审定的逻辑
      const note = "submitToApprovePass"
      this.$emit('submit-nextStage', row,note);
    }
  }
};
</script>
